package net.zabuchy.helper;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.zabuchy.user.action.UserAction;

import org.apache.log4j.Logger;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
 
public class MyAccessDeniedHandler implements AccessDeniedHandler {
	private String accessDeniedUrl;
 
	private static final Logger LOGGER = Logger.getLogger(MyAccessDeniedHandler.class.getName());
	
	public MyAccessDeniedHandler() {
	}
	
	public MyAccessDeniedHandler(String accessDeniedUrl) {
		this.accessDeniedUrl = accessDeniedUrl;
		LOGGER.debug("accessDeniedHandler");
	}
 
	@Override
	public void handle(HttpServletRequest request,
		HttpServletResponse response,
		AccessDeniedException accessDeniedException) throws IOException,
		ServletException {
		LOGGER.debug("accessDeniedHandler");
	   response.sendRedirect(accessDeniedUrl);
	   request.getSession().setAttribute("message",
		"You do not have permission to access this page!");
 
	}
 
	public String getAccessDeniedUrl() {
		return accessDeniedUrl;
	}
 
	public void setAccessDeniedUrl(String accessDeniedUrl) {
		this.accessDeniedUrl = accessDeniedUrl;
	}
}